package cn.com.huzo.repository.manufacture.impl;

import cn.com.huzo.model.entities.manufacture.CmtSettlementSlipHeaderEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.manufacture.CmtSettlementSlipHeaderRepository;

/**
 * 加工费计算信息数据访问对象。
 *
 * @author 吴旭
 */
@Repository("CmtSettlementSlipHeaderRepository")
public class CmtSettlementSlipHeaderRepositoryImpl extends GenericRepositoryImpl<CmtSettlementSlipHeaderEntity, Long>
        implements CmtSettlementSlipHeaderRepository {

    private final String namespace = "cn.com.huzo.repository.manufacture.CmtSettlementSlipHeaderRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public CmtSettlementSlipHeaderRepositoryImpl() {
        super(CmtSettlementSlipHeaderEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CmtSettlementSlipHeaderEntity fetchByKey(Long key) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByKey"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<CmtSettlementSlipHeaderEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String fetchNewBillNo() {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchNewBillNo"));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Long insert(CmtSettlementSlipHeaderEntity instance) {
        // 影响的行数
        int rowsAffected = getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);

        // 返回出入后的记录ID
        return instance.getHeaderId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer update(CmtSettlementSlipHeaderEntity instance) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "update"), instance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(Long key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
